/*
 * PagoscomerciosFijosFrame.java
 *
 * Created on 13 de abril de 2008, 11:44 AM
 */
package org.vehiculos.hipoteca;

import org.mybeans.Sesion;
 
import org.mybeans.ComerciosBeans;
import org.mybeans.ContribuyentesBeans;
import org.mybeans.RegimenBeans;
import org.mybeans.RecibesBeans;
import org.mybeans.RecibesDetallesBeans;
import org.mybeans.RecibesNumeracionBeans;

import org.mybeans.VehiculosBeans;
import org.mybeans.VehiculosInscripcionBeans;
import org.mybeans.VehiculosTraspasoNumeracionBeans;


import org.vehiculos.busquedas.VehiculosBusquedaSinHipotecaFrame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultCellEditor;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.swingx.autocomplete.*;

/**
 *
 * @author  avbravo
 */
public class VehiculosHipotecaSinPagoFrame extends javax.swing.JFrame {

    boolean focoVehiculo = false;
    boolean focoImpuesto = false;
    String reportSource;
    String reportDest;
    Sesion sesion;
    ComerciosBeans comerciosBeans;
    ContribuyentesBeans contribuyentesBeans;
    VehiculosBeans vehiculosBeans;
    VehiculosInscripcionBeans vehiculosInscripcionBeans;
    VehiculosTraspasoNumeracionBeans vehiculosTraspasoNumeracionBeans;
    String IdVehiculo;
    String TipoId = "vehiculos";
    private String idRegimen;
    String sql;
    int IdRecibo = 0;
    boolean TieneExoneracion = false;
    boolean TieneAlgunRegistroMoroso = false;
    String Estatus;
    int n;
    int paginas;
    String idEntidad;
    String Placa, residenciaOld = "", vendedor = "";

    /** Creates new form */
    public VehiculosHipotecaSinPagoFrame() {
        initComponents();
        sesion = new Sesion();
        /*
         * Fondo
         */

         
         
         

        jPanelFondo.setOpaque(false);
        setContentPane(jPanelFondo);
        /*
         * fondo
         */


        vehiculosBeans = new VehiculosBeans();
        comerciosBeans = new ComerciosBeans();
        contribuyentesBeans = new ContribuyentesBeans();
        vehiculosInscripcionBeans = new VehiculosInscripcionBeans();
        vehiculosTraspasoNumeracionBeans = new VehiculosTraspasoNumeracionBeans();


        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        jFormattedTextFieldFecha.setValue(mydate);
        sesion.setTipoId("comercios");


        jXDatePickerFechaHipoteca.setDate(mydate);


        //

        if (sesion.getPlaca() == null || sesion.getPlaca().equals("")) {
        } else {
            jTextFieldPlaca.setText(sesion.getPlaca());
            CargarVehiculos();
        }

        AutoCompleteDecorator.decorate(this.jComboBoxEntidad);
        CargarComboEntidad();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFondo = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jFormattedTextFieldFecha = new javax.swing.JFormattedTextField();
        jButtonRegresar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPlaca = new javax.swing.JTextField();
        jButtonBuscarVehiculos = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldMarca = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldModelo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldColor = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jRadioButtonContribuyente = new javax.swing.JRadioButton();
        jRadioButtonComercio = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldId = new javax.swing.JTextField();
        jTextFieldDueno = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jButtonImprimir = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonRegresar2 = new javax.swing.JButton();
        jComboBoxEntidad = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jXDatePickerFechaHipoteca = new org.jdesktop.swingx.JXDatePicker();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("HIPOTECA DE VEHICULOS SIN PAGO");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanelFondo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelFondo.setOpaque(false);
        jPanelFondo.setPreferredSize(new java.awt.Dimension(1007, 800));

        jLabel3.setText("Fecha");

        jFormattedTextFieldFecha.setEditable(false);
        jFormattedTextFieldFecha.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldFecha.setToolTipText("Fecha");
        jFormattedTextFieldFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldFechaActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel4.setText("Placa");

        jTextFieldPlaca.setColumns(35);
        jTextFieldPlaca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPlacaActionPerformed(evt);
            }
        });

        jButtonBuscarVehiculos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarVehiculos.setToolTipText("Buscar");
        jButtonBuscarVehiculos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarVehiculosActionPerformed(evt);
            }
        });

        jLabel5.setText("Marca");

        jTextFieldMarca.setEditable(false);
        jTextFieldMarca.setEnabled(false);

        jLabel7.setText("Modelo");

        jTextFieldModelo.setEditable(false);
        jTextFieldModelo.setEnabled(false);

        jLabel8.setText("Color");

        jTextFieldColor.setEditable(false);
        jTextFieldColor.setEnabled(false);

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setEnabled(false);

        jLabel16.setText("Dueño Anterior");

        jRadioButtonContribuyente.setSelected(true);
        jRadioButtonContribuyente.setText("Contribuyente");
        jRadioButtonContribuyente.setEnabled(false);
        jRadioButtonContribuyente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonContribuyenteMouseClicked(evt);
            }
        });

        jRadioButtonComercio.setText("Comercio");
        jRadioButtonComercio.setEnabled(false);
        jRadioButtonComercio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonComercioMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel16)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonContribuyente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonComercio)
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel16)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButtonComercio)
                .addComponent(jRadioButtonContribuyente))
        );

        jLabel9.setText("Identificador");

        jTextFieldId.setEditable(false);
        jTextFieldId.setEnabled(false);

        jTextFieldDueno.setEditable(false);
        jTextFieldDueno.setEnabled(false);

        jLabel10.setText("Dueño");

        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonImprimir.setToolTipText("Guardar");
        jButtonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimirActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonRegresar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar2.setToolTipText("Regresar");
        jButtonRegresar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresar2ActionPerformed(evt);
            }
        });

        jComboBoxEntidad.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxEntidadItemStateChanged(evt);
            }
        });
        jComboBoxEntidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxEntidadActionPerformed(evt);
            }
        });

        jLabel11.setText("Entidad");

        jLabel12.setText("Fecha Hipoteca");

        jLabel13.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel13.setText("Hipoteca");

        javax.swing.GroupLayout jPanelFondoLayout = new javax.swing.GroupLayout(jPanelFondo);
        jPanelFondo.setLayout(jPanelFondoLayout);
        jPanelFondoLayout.setHorizontalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanelFondoLayout.createSequentialGroup()
                                            .addComponent(jLabel5)
                                            .addGap(25, 25, 25)
                                            .addComponent(jTextFieldMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanelFondoLayout.createSequentialGroup()
                                            .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel7)
                                                .addComponent(jLabel8))
                                            .addGap(18, 18, 18)
                                            .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jTextFieldColor, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jButtonBuscarVehiculos, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(37, 37, 37)
                                        .addComponent(jLabel3)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonRegresar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGap(96, 96, 96)
                                .addComponent(jLabel13))
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel11))
                                .addGap(18, 18, 18)
                                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jXDatePickerFechaHipoteca, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBoxEntidad, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGap(84, 84, 84)
                                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonRegresar2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(54, 54, 54))
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldDueno, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(132, 132, 132)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPanelFondoLayout.setVerticalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonBuscarVehiculos)
                    .addComponent(jLabel3)
                    .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonRegresar))
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(jLabel8))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(3, 3, 3))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldDueno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jComboBoxEntidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33))
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(jXDatePickerFechaHipoteca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonRegresar2, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jButtonLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                        .addComponent(jButtonImprimir, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.PREFERRED_SIZE, 661, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.PREFERRED_SIZE, 421, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    this.dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jFormattedTextFieldFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldFechaActionPerformed
}//GEN-LAST:event_jFormattedTextFieldFechaActionPerformed

private void jButtonRegresar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresar2ActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresar2ActionPerformed

private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed

    try {
        if (ValidarEntradas() == false) {
            return;
        }


        /*
         * guardar el recibo
         * 
         */
        IdVehiculo = vehiculosBeans.getIdVehiculo();



        GuardarHipoteca();



        jButtonImprimir.setEnabled(false);



    } catch (Exception ex) {
        sesion.MostrarMensajeError("Error ", "Metodo:  jButtonImprimirActionPerformed()\n " + ex.getMessage().toString());
    }

}//GEN-LAST:event_jButtonImprimirActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed

    Limpiar();

}//GEN-LAST:event_jButtonLimpiarActionPerformed

    private void Actualizar() {
        try {

            jTextFieldPlaca.setText(vehiculosBeans.getPlaca());
            this.Placa = vehiculosBeans.getPlaca();
            jTextFieldMarca.setText(vehiculosBeans.getMarca());
            jTextFieldModelo.setText(vehiculosBeans.getModelo());
            jTextFieldColor.setText(vehiculosBeans.getColor());
            jTextFieldId.setText(vehiculosBeans.getId());
            jTextFieldDueno.setText(vehiculosBeans.getDueno());
            this.vendedor = vehiculosBeans.getDueno();

            String TipoId = vehiculosBeans.getTipoId();
            String idOld = vehiculosBeans.getId();
            TipoId = TipoId.toLowerCase();
            if (TipoId.equals("contribuyentes")) {
                jRadioButtonContribuyente.setSelected(true);
                jRadioButtonComercio.setSelected(false);

            } else {
                if (TipoId.equals("comercios")) {
                    jRadioButtonContribuyente.setSelected(false);
                    jRadioButtonComercio.setSelected(true);

                }
            }
            repaint();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
    try {

        if (focoImpuesto) {
            if (sesion.getSeleccionado().equals("si")) {
            }
        } else {
            if (focoVehiculo) {
                Actualizar();
            }

        }
        focoImpuesto = false;
        focoVehiculo = false;
    } catch (Exception ex) {
        sesion.MostrarMensajeError("Error ", "formWindowGainedFocus()\nError " + ex.getMessage().toString());
    }
}//GEN-LAST:event_formWindowGainedFocus

private void jTextFieldPlacaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPlacaActionPerformed

    CargarVehiculos();
}//GEN-LAST:event_jTextFieldPlacaActionPerformed

private void jButtonBuscarVehiculosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarVehiculosActionPerformed

    VehiculosBusquedaSinHipotecaFrame vehiculosBusquedaSinHipotecaFrame = new VehiculosBusquedaSinHipotecaFrame();
    vehiculosBusquedaSinHipotecaFrame.setLocationRelativeTo(null);
    vehiculosBusquedaSinHipotecaFrame.setVisible(true);
    focoVehiculo = true;
}//GEN-LAST:event_jButtonBuscarVehiculosActionPerformed

private void jRadioButtonContribuyenteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonContribuyenteMouseClicked
}//GEN-LAST:event_jRadioButtonContribuyenteMouseClicked

private void jRadioButtonComercioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonComercioMouseClicked
}//GEN-LAST:event_jRadioButtonComercioMouseClicked

private void jComboBoxEntidadItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxEntidadItemStateChanged
}//GEN-LAST:event_jComboBoxEntidadItemStateChanged

private void jComboBoxEntidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxEntidadActionPerformed

    try {
        String temp = (String) jComboBoxEntidad.getSelectedItem();
        if (temp == null || temp.equals("")) {
        } else {

            int posicion = temp.indexOf("|");

            int posfinal = 0;
            if (posicion <= 0) {
                posfinal = 0;
            } else {
                posfinal = posicion - 1;
            }

            String entidad = temp.substring(0, posfinal);
            int tamano = temp.length();
            int nuevaposicion = posfinal + 2;
            String idEntidad = temp.substring(nuevaposicion, tamano);

            this.idEntidad = idEntidad;

        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox SubGrupoRegimen ActionPerformed", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jComboBoxEntidadActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VehiculosHipotecaSinPagoFrame().setVisible(true);
            }
        });
    }

    /*
     * 
     *verifica si ya se pago la placa para este año 
     * 
     */
    private void LimpiarComercios() {
        jTextFieldPlaca.setText("");
        jTextFieldMarca.setText("");
        jTextFieldModelo.setText("");
        jTextFieldColor.setText("");
        jTextFieldId.setText("");
        jTextFieldDueno.setText("");
    }

    private void Limpiar() {
        try {


            LimpiarRegimen();
            LimpiarComercios();

        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Limpiar()\n " + ex.getMessage().toString());
        }
    }

    public void LimpiarRegimen() {
        //jTextFieldIdRegimen.setText("");
    }

    private boolean ValidarEntradas() {
        try {

            IdVehiculo = this.jTextFieldPlaca.getText();

            if (IdVehiculo == null || IdVehiculo.equals("")) {
                JOptionPane.showMessageDialog(this, "No ha seleccionado un comercio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldPlaca.requestFocus();
                return false;
            }


            String Marca = this.jTextFieldMarca.getText();
            if (Marca == null || Marca.equals("")) {
                JOptionPane.showMessageDialog(this, "No ha seleccionado ningun vehiculo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldPlaca.requestFocus();
                return false;
            }

            if (this.idEntidad == null || this.idEntidad.equals("")) {
                JOptionPane.showMessageDialog(this, "No ha seleccionado ninguna entidad...", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jComboBoxEntidad.requestFocus();
                return false;
            }

            /*
             *Evaluar cuando selecciona una exoneracion y no marca ningun valor exonerado
             *
             */

            String sFecha = jFormattedTextFieldFecha.getText();
            if (sFecha == null || sFecha.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione la fecha ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jFormattedTextFieldFecha.requestFocus();
            }





            return true;
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ValidarEntradas()\n " + ex.getMessage().toString());
        }
        return false;
    }

    private void CargarVehiculos() {

        try {
            String Placa = this.jTextFieldPlaca.getText();
            if (Placa == null || Placa.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la placa del vehiculo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            vehiculosBeans.setPlaca(Placa);

            if (vehiculosBeans.ConsultarPorPlaca() == true) {

                if (vehiculosBeans.getPlaca() == null || vehiculosBeans.getPlaca().equals("")) {
                    JOptionPane.showMessageDialog(this, "Este vehiculo no tiene asiganda una placa...", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }

                jTextFieldId.setText(vehiculosBeans.getId());
                //-----------------------------------
                //----   Verifica el estatus     ----
                //-----------------------------------
                String Nota = "Este vehiculo ";
                String hipoteca = "";
                String secuestro = "";
                if (vehiculosBeans.getHipotecado().equals("si")) {
                    hipoteca = "registra hipoteca y";
                    JOptionPane.showMessageDialog(this, "Este vehiculo tiene hipoteca registrada  ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    this.jTextFieldPlaca.setText("");
                    return;
                } else {
                    hipoteca = "no registra hipoteca y";
                }
                if (vehiculosBeans.getSecuestrado().equals("si")) {
                    secuestro = "registra caso judicial pendiente";

                } else {
                    secuestro = "no registra caso judicial pendiente";
                }


                Nota = Nota + " " + hipoteca + " " + secuestro;

                vehiculosBeans.setTipoId(vehiculosBeans.getTipoId().toLowerCase());
                if (vehiculosBeans.getTipoId().equals("contribuyentes")) {
                    ContribuyentesCargar();
                    jRadioButtonContribuyente.setSelected(true);
                    jRadioButtonComercio.setSelected(false);
                } else {
                    if (vehiculosBeans.getTipoId().equals("comercios")) {
                        ComerciosCargar();
                        jRadioButtonContribuyente.setSelected(false);
                        jRadioButtonComercio.setSelected(true);
                    }
                }

                Actualizar();

            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }


    }

    private void ContribuyentesCargar() {
        try {
            String cedula = this.jTextFieldId.getText();
            if (cedula == null || cedula.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la cedula del contribuyente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String sqlquery = "select * from contribuyentes where idmunicipio = ? and cedula = ?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, sesion.getIdmunicipio());
            psquery.setString(2, cedula);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
                JOptionPane.showMessageDialog(this, "No existen registros de contribuyentes con esa cedula", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String activo = rs.getString("activo");
            if (activo.equals("no")) {
                JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            contribuyentesBeans.setCedula(cedula);
            contribuyentesBeans.setContribuyente(rs.getString("contribuyente"));
            contribuyentesBeans.setIdSeguroSocial(rs.getString("idsegurosocial"));
            contribuyentesBeans.setOcupacion(rs.getString("ocupacion"));
            contribuyentesBeans.setNacionalidad(rs.getString("nacionalidad"));
            contribuyentesBeans.setIdMunicipio(rs.getString("idmunicipio"));
            contribuyentesBeans.setIdCorregimiento(rs.getString("idcorregimiento"));
            contribuyentesBeans.setDomicilio(rs.getString("domicilio"));
            contribuyentesBeans.setCasa(rs.getString("casa"));
            contribuyentesBeans.setTelefono(rs.getString("telefono"));
            contribuyentesBeans.setApartadoPostal(rs.getString("apartadopostal"));
            contribuyentesBeans.setEmail(rs.getString("email"));
            contribuyentesBeans.setObservacion(rs.getString("observacion"));
            contribuyentesBeans.setIdMunicipioVive(rs.getString("idmunicipiovive"));
            contribuyentesBeans.setIdCorregimientoVive(rs.getString("idcorregimientovive"));
            contribuyentesBeans.setActivo(rs.getString("activo"));
            contribuyentesBeans.setFoto(rs.getString("foto"));



            if (contribuyentesBeans.getContribuyente() == null || contribuyentesBeans.getContribuyente().equals("")) {
                JOptionPane.showMessageDialog(this, "El contribuyente esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }

            jTextFieldDueno.setText(contribuyentesBeans.getContribuyente());
            vehiculosBeans.setDueno(contribuyentesBeans.getContribuyente());

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void ComerciosCargar() {
        try {
            String IdComercio = this.jTextFieldId.getText();
            if (IdComercio == null || IdComercio.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el codigo del comercio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String sqlquery = "select comercios.*, contribuyentes.contribuyente from comercios, contribuyentes where comercios.idmunicipio = ? and comercios.idcomercio = ? and comercios.cedula = contribuyentes.cedula";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, sesion.getIdmunicipio());
            psquery.setString(2, IdComercio);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
                JOptionPane.showMessageDialog(this, "No existen registros de comercios con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String comercio = rs.getString("comercio");
            String cedula = rs.getString("cedula");
            String contribuyente = rs.getString("contribuyente");
            String Ruc = rs.getString("ruc");
            String Descripcion = rs.getString("descripcion");
            String Direccion = rs.getString("direccion");
            String IdCorregimiento = rs.getString("idcorregimiento");
            String Telefono = rs.getString("telefono");
            String Hipotecado = rs.getString("hipotecado");
            String Bajado = rs.getString("bajado");
            String Traspaso = rs.getString("traspaso");
            String Estatal = rs.getString("estatal");
            String Secuestrado = rs.getString("secuestrado");
            String Activo = rs.getString("activo");

            jTextFieldDueno.setText(comercio);

            if (comercio == null || comercio.equals("")) {
                JOptionPane.showMessageDialog(this, "El comercio esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }

            comerciosBeans.setIdComercio(IdComercio);
            comerciosBeans.setComercio(comercio);
            comerciosBeans.setCedula(cedula);
            comerciosBeans.setContribuyente(contribuyente);
            comerciosBeans.setRuc(Ruc);
            comerciosBeans.setDescripcion(Descripcion);
            comerciosBeans.setDireccion(Direccion);
            comerciosBeans.setIdCorregimiento(IdCorregimiento);
            comerciosBeans.setTelefono(Telefono);
            comerciosBeans.setHipotecado(Hipotecado);
            comerciosBeans.setBajado(Bajado);
            comerciosBeans.setTraspaso(Traspaso);
            comerciosBeans.setEstatal(Estatal);
            comerciosBeans.setSecuestrado(Secuestrado);
            comerciosBeans.setActivo(Activo);
            vehiculosBeans.setDueno(comerciosBeans.getComercio());
            repaint();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarComboEntidad() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select entidad.* from entidad where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by entidad";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxEntidad.removeAllItems();
            int count = 0;
            jComboBoxEntidad.insertItemAt("", count);
            count = 1;
            while (rs.next()) {
                String entidad = rs.getString("entidad");
                entidad = entidad + " | " + rs.getString("identidad");
                jComboBoxEntidad.insertItemAt(entidad, count);
                count++;
            }
            if (count != 0) {
                jComboBoxEntidad.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void GuardarHipoteca() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
              if (this.idEntidad == null || this.idEntidad.equals("")){
                JOptionPane.showMessageDialog(this, "Mensaje: no existe un codigo de entidad", "Advertencia", JOptionPane.WARNING_MESSAGE);
                return;

            }
            this.idEntidad = this.idEntidad.trim();
  int NumeroEntidad = Integer.parseInt(this.idEntidad);



            String sql = "update  vehicles set hipotecado='si' where idmunicipio = ? and idvehiculo = ? and activo='si'";

            PreparedStatement prest1 = sesion.con.prepareStatement(sql);
            prest1.setString(1, sesion.getIdmunicipio()); //placa
            prest1.setInt(2, Integer.parseInt(this.IdVehiculo));

            int count1 = prest1.executeUpdate();


            java.util.Date FechaDate = jXDatePickerFechaHipoteca.getDate();
            java.sql.Date FechaHipoteca = new java.sql.Date(FechaDate.getTime());
            if (FechaHipoteca == null) {
                JOptionPane.showMessageDialog(this, "Ingrese la fecha de hipoteca...", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jXDatePickerFechaHipoteca.requestFocus();
                return;
            }
            sql = "INSERT into vehicleshipoteca (idvehiculo,placa,idrecibo,fechahipoteca,identidad,activo,idmunicipio,fecha,username) VALUES(?,?,?,?,?,?,?,?,?)";
            PreparedStatement prest = sesion.con.prepareStatement(sql);
            prest.setString(1, this.IdVehiculo); //
            prest.setString(2, this.Placa);
            prest.setInt(3, this.IdRecibo);
            prest.setDate(4, FechaHipoteca);//FECHA HIPOTECA
            prest.setInt(5, NumeroEntidad); //
            prest.setString(6, "si");
            prest.setString(7, sesion.getIdmunicipio());
            java.util.Calendar ca = java.util.Calendar.getInstance();
            java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
            prest.setDate(8, mydate); //fechatraspaso
            prest.setString(9, sesion.getUsername());


            int count = prest.executeUpdate();


            sesion.con.close();
            JOptionPane.showMessageDialog(this, "Hipoteca registrada exitosamente...", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

        } catch (Exception ex) {
            System.out.println("Error" + ex);
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBuscarVehiculos;
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonRegresar2;
    private javax.swing.JComboBox jComboBoxEntidad;
    private javax.swing.JFormattedTextField jFormattedTextFieldFecha;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanelFondo;
    private javax.swing.JRadioButton jRadioButtonComercio;
    private javax.swing.JRadioButton jRadioButtonContribuyente;
    private javax.swing.JTextField jTextFieldColor;
    private javax.swing.JTextField jTextFieldDueno;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldMarca;
    private javax.swing.JTextField jTextFieldModelo;
    private javax.swing.JTextField jTextFieldPlaca;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFechaHipoteca;
    // End of variables declaration//GEN-END:variables
}
